package com.app.fenak;

import com.app.fenak.asynctasks.LoginAsyncTask;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class LoginActivity extends Activity {

	private EditText password;
	private Button loginButton;
	private TextView forgetPassword;
	private ProgressDialog progressDialog;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);

		setContentView(R.layout.password);

		password = (EditText) findViewById(R.id.login_password);
		loginButton = (Button) findViewById(R.id.login_button);
		forgetPassword = (TextView) findViewById(R.id.forget_password_text);
	}

	@Override
	protected void onStart() {

		super.onStart();

		forgetPassword.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				Intent intent = new Intent(getApplicationContext(),
						ForgetPasswordActivity.class);
				startActivity(intent);

			}
		});

		loginButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				String password = LoginActivity.this.password.getText()
						.toString();
				String email = getSharedPreferences(
						getString(R.string.pref_name), Context.MODE_PRIVATE)
						.getString(getString(R.string.email_pref), "");

				progressDialog = ProgressDialog.show(LoginActivity.this, "",
						getString(R.string.login_dialog));
				new LoginAsyncTask().execute(LoginActivity.this, email,
						password);

			}
		});

	}

	public void dismissProgressDialog() {
		if (this.progressDialog != null) {
			this.progressDialog.dismiss();
		}
	}

}
